package stark.app.frame.document;

/**
 *      https://x5.tencent.com/tbs/product/file.html
 * */

import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.ValueCallback;

import org.w3c.dom.Text;

import stark.app.frame.TextItemBean;
import stark.app.frame.document.poiexcel.CreateExcelDemoActivity;
import stark.app.uibase.BaseListActivity;
import stark.common.basic.utils.FileUtil;

public class DocumentActivity extends BaseListActivity {

    String[] mArrSuffix = {
            ".txt",".pdf",".docx",".xlsx",".pptx"
    };

    @Override
    protected void initData() {
        super.initData();
        mAdapter.addData(new TextItemBean("Excel POI"));
        mAdapter.addData(new TextItemBean("查看txt文件"));
        mAdapter.addData(new TextItemBean("查看pdf文件"));
        mAdapter.addData(new TextItemBean("查看docx文件"));
        mAdapter.addData(new TextItemBean("查看xlsx文件"));
        mAdapter.addData(new TextItemBean("查看pptx文件"));

    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if(position==0){
            startActivity(new Intent(this, CreateExcelDemoActivity.class));
        }else {
            String name = "test" + mArrSuffix[position-1];
            String path = FileUtil.getAssetsCacheFile(this, name);
            QbSDKViewerActivity.startDocumentViewer(this, path, mArrSuffix[position-1]);
        }
//        QbSdk.openFileReader(DocumentActivity.this,  path, null, new ValueCallback<String>() {
//            @Override
//            public void onReceiveValue(String s) {
//                System.out.println(s);
//            }
//        });
    }
}